function backPropData = feedForward(pattern, weightsVector, solution)
    global LAYERS;
%TRAINSIMPLEPERCEPTRON
%   This function trains a simple perceptron with a given pattern, a 
%   weights vector, the expected 
%   solution for each pattern (b). An exitation function (g)
%   and its derived function (gp) and compute de deltas for the output
%   layer
%   
%   Input
%
%   pattern: The pattern to train
%   weightsVector: The array of matrixes of weights for each layer.
%
%   Output:
%   wf: The array of matrixes of the trained weigths.
%

	nOfLayers = length(LAYERS);
    backPropData = cell(1,2);
    backPropData{1} = cell(1, nOfLayers);

	% PROPAGATE SIGNAL
    layerNeurons = pattern;
    for j = 1:nOfLayers                                         % for each layer, obtain output of the units in that layer and propagate! We add the -1 as the threshold
        hj = weightsVector{j}*vertcat(-1, layerNeurons);        % select matrix_j which represents weights between units in layer j and its predecesor units + thresholds
        backPropData{1}{j} = hj;
        layerNeurons = g_function(hj);
    end
    backPropData{2} = gp_function(hj).*(solution - layerNeurons);
end

%---------------------------------
%Funcion recursiva de Augusto
%---------------------------------
%function O = feedForward(pattern, leyer, fnc)
%Funci?n que evalua una red neuronal feed-fordward
%multicapa.
% Recibe como input un pattern vector de 1*k columnas,
% y un array (leyer) de pesos de tal manera que la cantidad de
% filas del input anterior sea 1 + la cantida de columnas
% de los pesos siguientes. Esto es porque en cada evaluaci?n
% se cablea el umbral en -1 y se pierde para la proxima evaluaci?n
% Ej:
%   
%   pattern: [0 1]      1x2
%   leyer(1) = [ 1 1 2 ;2 3 3] 3*2 (fxc)
%   leyer(2) = [ 8 ; 9 ; 10] (c+1)*1 
%   
%   pattern: patron del entrada a la red.
%   leyer: array de capas de neuronas (la primera es la primera cada)
%       representada cada neurona como una culumna de pesos de entrada.
%   fnc: funci?n de activaci?n de las neuronas.
%
%    len = length(leyer);
%
%    if(len == 1)
%        O = fnc(horzcat(-1,pattern)*leyer{1});
%    else
%        w = leyer{len};
%        leyer(len) = [];
%        O = fnc(horzcat(-1, evalNet(pattern, leyer, fnc))*w);
%    end
%end

